package com.alm.token.ui.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextUtils;
import android.text.TextWatcher;
import android.view.MotionEvent;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.EditText;
import android.widget.TextView;

import com.alm.token.ConStant;
import com.alm.token.GlideApp;
import com.alm.token.R;
import com.alm.token.base.BaseActivity;
import com.alm.token.ui.data.bean.AddDrawData;
import com.alm.token.ui.data.bean.DrawIndexData;
import com.alm.token.ui.data.bean.RegisterData;
import com.alm.token.ui.data.bean.TransferTransData;
import com.alm.token.ui.data.bean.TurnOutBiTB_QRdata;
import com.alm.token.ui.data.bean.UserWalletData;
import com.alm.token.ui.persenter.MyPreenter;
import com.alm.token.ui.view.TurmOutView;
import com.alm.token.utils.ActionBarHelper;
import com.alm.token.utils.CommonUtil;
import com.alm.token.utils.EmptyUtils;
import com.alm.token.utils.LogUtil;
import com.alm.token.utils.Utils;
import com.google.gson.Gson;

import java.math.BigDecimal;
import java.text.DecimalFormat;

import baibeiwallet.Constant;
import baibeiwallet.utils.DialogUtils;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;
import butterknife.OnFocusChange;

//import com.uuzuche.lib_zxing.activity.CaptureActivity;
//import com.uuzuche.lib_zxing.activity.CodeUtils;
//import com.uuzuche.lib_zxing.activity.ZXingLibrary;

public class TurnOutBiTB_shoukuanren_Activity extends BaseActivity implements TextWatcher, TurmOutView<Object> {


    @BindView(R.id.edt_inputadress)
    EditText edtInputadress;
    @BindView(R.id.tv_outmoneynext)
    TextView tvOutmoneynext;

    @Override
    protected MyPreenter initPreenter() {
        return new MyPreenter(this);
    }

    @Override
    protected int getContentViewId() {
        return R.layout.activity_turnout_shoukuanren;
    }

    @Override
    protected void initVariables() {
    }

    @Override
    protected void initViews() {
//        new ActionBarHelper(this).setTitle(getString(R.string.app_hint_superegg));
        new ActionBarHelper(this).setTitle(getString(R.string.tv_hint_shoukuanuser));
        edtInputadress.addTextChangedListener(this);
    }

    @Override
    protected void loadData() {

    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {

            case R.id.tv_outmoneynext:

                if (EmptyUtils.isNotEmpty(edtInputadress.getText().toString())) {
                    shoukuanren = edtInputadress.getText().toString();
                    preenter.getcheckLoginNameData(shoukuanren);
                }

                break;
        }
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        // TODO: add setContentView(...) invocation
        ButterKnife.bind(this);
    }

    @Override
    public void beforeTextChanged(CharSequence s, int start, int count, int after) {

    }

    @Override
    public void onTextChanged(CharSequence s, int start, int before, int count) {
        if (EmptyUtils.isNotEmpty(s)) {
            tvOutmoneynext.setBackground(getResources().getDrawable(R.drawable.gradient_btn));
            tvOutmoneynext.setText(getString(R.string.tv_hint_next));
            tvOutmoneynext.setOnClickListener(this);
        } else {
            tvOutmoneynext.setBackground(getResources().getDrawable(R.drawable.gradient_btn_unclick));
            tvOutmoneynext.setText(getString(R.string.currency_hint1_warn));
            tvOutmoneynext.setOnClickListener(null);
        }
    }

    @Override
    public void afterTextChanged(Editable s) {
    }


    @Override
    public void getData(Object o) {

    }

    @Override
    public void jumpToLoginAct(int staue) {
        if (staue == 3) {
//            showToast(getString(R.string.common_relogin));
//            Intent intent = new Intent();
//            intent.setAction(ConStant.EXIT_APP);
//            sendBroadcast(intent);
//            startActivity(BlockWalletLoginActivity.class);
//            finish();
        } else if (staue == 4) {
//            showToast(getString(R.string.paypasw_hint_setpaypsw));
//            Intent intent = new Intent(this,PayPwdActivity.class);
//            intent.putExtra("PayPwdActivityType",PayPwdActivity.PAYPSW_SET);
//            startActivity(intent);
//            finish();
            showToSetPaypswDialog();
        } else if (staue == 666) {
            showToUpdata();
        }
    }

    @Override
    public void onError(String error) {
        showToast(error);
    }

    @Override
    public void ShowProgress() {
        showWaitDialog();
    }

    @Override
    public void hideProgress() {
        hideWaitDialog();
    }

    @Override
    public void getDrawIndexData(DrawIndexData drawIndexData) {

    }

    @Override
    public void getAddDrawData(AddDrawData addDrawData) {

    }

    @Override
    public void getCode(RegisterData registerData) {

    }

    @Override
    public void getTransferIndexData(DrawIndexData drawIndexData) {

    }

    @Override
    public void getTransfertransData(TransferTransData transferTransData) {

    }

    @Override
    public void getcheckLoginNameData(RegisterData checkLoginNameData) {

        if (checkLoginNameData.getStatus() == 0) {

            String result = "{\"coinId\":\"\",\"type\":\"CollectionPayment\",\"price\":\"\",\"address\":\"" + shoukuanren + "\",\"coinName\":\"\"}";
            //说明是比币互转付款二维码扫码
            Intent intent = new Intent(this, TurnOutBiTB_FukuanActivity.class);
            intent.putExtra("scanResult", result + "");
            startActivity(intent);
            finish();

        } else {
            showToast(checkLoginNameData.getMsg());
        }
    }


    String shoukuanren = "";

}
